<?php

namespace AppBundle\DataFixtures\ORM;

use \Doctrine\Common\DataFixtures\AbstractFixture;
use \Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use \Doctrine\Common\Persistence\ObjectManager;
use \Doctrine\Bundle\FixturesBundle\Fixture;
use AppBundle\Entity\Product as Product;

class LoadProductData extends Fixture
{
    /**
     *
     * {@inheritDoc}
     */
    public function load(ObjectManager $manager)
    {
        // create some mormal data
        for ($i = 10000; $i <= 10099; $i++) {
            $p = new Product();
            $p->setName('Normal Book Title');
            $p->setPrice("$i.99");
            $p->setDescription('This is a normal book.');
            $p->setCategory($this->getReference('commonPub'));
            $manager->persist($p);
        }

        // create a special data
        $p1 = new Product();
        $p1->setName('special Book Title');
        $p1->setPrice("$i.99");
        $p1->setDescription('This is a special book.');
        $p1->setCategory($this->getReference('specialPub'));
        $this->addReference('aBook', $p1);
        $manager->persist($p1);

        // insert many dates into database 
        $manager->flush();
    }

    /**
     *
     * {@inheritDoc}
     */
    public function getOrder()
    {
        return 2;
    }
}
